<?php
include './config.inc.php';
include './include/db_mysql.class.php';
$ucdb = new dbstuff;
$ucdb->connect(UC_DBHOST, UC_DBUSER, UC_DBPW, UC_DBNAME, $pconnect);

$db = new dbstuff;
$db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect);
unset($dbhost, $dbuser, $dbpw, $dbname, $pconnect);

function getmaxuid() {
	global $ucdb;
	$query = $ucdb->query("SHOW CREATE TABLE ".UC_DBTABLEPRE."members");
	$data = $ucdb->fetch_array($query);
	//print_r( $data );
	$data = $data['Create Table'];
	if(preg_match('/AUTO_INCREMENT=(\d+?)[\s|$]/i', $data, $a)) {
		return $a[1]-1;
	} else {
		return 0;
	}
}

$maxuid = getmaxuid();

$query = $db->query("SELECT * FROM user_basic_info");

while($data = $db->fetch_array($query)) {
	$salt = rand(100000, 999999);
	$password = md5( $data['pwd'].$salt);
	$data['nick'] = addslashes($data['nick']);
	$lastuid = $data['id'] += $maxuid;
	$queryuc = $ucdb->query("SELECT count(*) FROM ".UC_DBTABLEPRE."members WHERE username='$data[nick]'");
	$userexist = $ucdb->result($queryuc, 0);
	if(!$userexist) {
		$sql = "INSERT LOW_PRIORITY INTO ".UC_DBTABLEPRE."members SET uid='$data[id]', username='$data[nick]', password='$password', email='$data[email]', regip='127.0.0.1', regdate='$data[register_date]', salt='$salt'";
		$ucdb->query( $sql,'SILENT' );
		echo $sql;
		$ucdb->query("INSERT LOW_PRIORITY INTO ".UC_DBTABLEPRE."memberfields SET uid='$data[id]'",'SILENT');
	} else {
		$ucdb->query("REPLACE INTO ".UC_DBTABLEPRE."mergemembers SET appid='".UC_APPID."', username='$data[nick]'", 'SILENT');
	}
}

$ucdb->query("ALTER TABLE ".UC_DBTABLEPRE."members AUTO_INCREMENT=".($lastuid + 1));

?>
